What is HCL?

Author

Hans Lehndorff

Modified

February 16, 2023

HCL is a colorspace which is better than RGB for creating perceptually uniform colors.

The polarLUV function from the colorspace package, takes hue, chroma and luminance inputs and returns a color hexcode (via the hex function). Based on testing, polarLUV:

This process goes through a range of hues and generates a sample combinations of chroma and luminance.

library(tidyverse)
library(colorspace)

# -134:107

output<-NULL
for(h in seq(-134,107,16)){
  # print(h)
  z=expand.grid(
  l=seq(1,150,.1),#
  c=seq(-200,200,.1) #
  ) %>% 
    mutate(
      h=h,
      color=hex(polarLUV(H=h,C=c,L=l))
      ) %>% 
    filter(!is.na(color)) %>% #
    slice_sample(n=10000,replace = T) %>% 
    distinct()
  
  output<-bind_rows(output,z)
  
}

A plot showing the impact on color of chroma and luminance on a selection of hues.

Show code
ggplot(output)+
  geom_point(aes(x=l,y=c),color=output$color)+
  geom_hline(yintercept = 0, linetype=2)+
  theme_minimal()+
  labs(x="Luminance",y="Chroma",title="Impact of Luminance and Chroma variation for a sample of Hues")+
  facet_wrap(h~.)

Using plotly, the HCL color space can be viewed interactively in three dimensions.

Show code
output2<-NULL
for(h in seq(-150,123,16)){
  # print(h)
  z=expand.grid(
  l=seq(1,150,10),#
  c=seq(-200,200,10) #
  ) %>% 
    mutate(
      h=h,
      color=hex(polarLUV(H=h,C=c,L=l))
      ) %>% 
    filter(!is.na(color)) %>% #
    slice_sample(n=10000,replace = T) %>% 
    distinct()
  
  output2<-bind_rows(output2,z)
  
}

library(plotly)
output2<-output2 %>% 
  # filter(c>0) %>% 
  arrange(color) %>% ungroup()
plot_ly(output2,x=~h,y=~l,z=~c,color=~color,colors = unique(output2$color))